package com.flyqiu.form.spring.boot.starter;

import com.flyqiu.form.api.col.FlyQiuStoreColTypeManage;
import com.flyqiu.form.api.event.FlyQiuTableDataEventManage;
import com.flyqiu.form.api.event.FlyQiuTableEventManage;
import com.flyqiu.form.api.rule.FlyQiuDataRuleManage;
import com.flyqiu.form.api.service.FlyQiuTableConfigService;
import com.flyqiu.form.api.store.FlyQiuAvueDynamicService;
import com.flyqiu.form.api.store.FlyQiuFormCoreService;
import com.flyqiu.form.api.store.FlyQiuFormStoreManage;
import com.flyqiu.form.core.FlyQiuFormCoreServiceImpl;
import com.flyqiu.form.core.col.DefaultFlyQiuStoreColTypeManage;
import com.flyqiu.form.core.event.DefaultFlyQiuDataEventManage;
import com.flyqiu.form.core.event.DefaultFlyQiuEventManage;
import com.flyqiu.form.core.rule.DefaultFlyQiuDataRuleManage;
import com.flyqiu.form.core.service.FlyQiuTableConfigServiceImpl;
import com.flyqiu.form.core.storage.DefaultFlyQiuFormStoreManage;
import com.flyqiu.form.core.storage.FlyQiuAvueDynamicServiceImpl;
import com.flyqiu.form.mapper.FlyQiuTableConfigMapper;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 自动配置类，用于自动装配 FlyQiu 表单管理相关的 Bean。
 */
@Configuration
@MapperScan(basePackageClasses = {FlyQiuTableConfigMapper.class})
public class SpringFlyQiuFormManageAutoConfig {

    private static final Logger logger = LoggerFactory.getLogger(SpringFlyQiuFormManageAutoConfig.class);

    /**
     * 创建 FlyQiuTableEventManage 实例。
     *
     * @return FlyQiuTableEventManage 实例
     */
    @Bean
    @ConditionalOnMissingBean(FlyQiuTableEventManage.class)
    public FlyQiuTableEventManage flyQiuFormEventManage() {
        logger.info("Creating FlyQiuTableEventManage");
        return new DefaultFlyQiuEventManage();
    }

    /**
     * 创建 FlyQiuTableDataEventManage 实例。
     *
     * @return FlyQiuTableDataEventManage 实例
     */
    @Bean
    @ConditionalOnMissingBean(FlyQiuTableDataEventManage.class)
    public FlyQiuTableDataEventManage flyQiuFormDataEventManage() {
        logger.info("Creating FlyQiuTableDataEventManage");
        return new DefaultFlyQiuDataEventManage();
    }

    /**
     * 创建 FlyQiuFormStoreManage 实例。
     *
     * @return FlyQiuFormStoreManage 实例
     */
    @Bean
    @ConditionalOnMissingBean(FlyQiuFormStoreManage.class)
    public FlyQiuFormStoreManage flyQiuformStoreManage() {
        logger.info("Creating FlyQiuFormStoreManage");
        return new DefaultFlyQiuFormStoreManage();
    }

    /**
     * 创建 FlyQiuDataRuleManage 实例。
     *
     * @return FlyQiuDataRuleManage 实例
     */
    @Bean
    @ConditionalOnMissingBean(FlyQiuDataRuleManage.class)
    public FlyQiuDataRuleManage flyQiuDataRuleManage() {
        logger.info("Creating FlyQiuDataRuleManage");
        return new DefaultFlyQiuDataRuleManage();
    }

    /**
     * 创建 FlyQiuStoreColTypeManage 实例。
     *
     * @return FlyQiuStoreColTypeManage 实例
     */
    @Bean
    @ConditionalOnMissingBean(FlyQiuStoreColTypeManage.class)
    public FlyQiuStoreColTypeManage flyQiuStoreColTypeManage() {
        logger.info("Creating FlyQiuStoreColTypeManage");
        return new DefaultFlyQiuStoreColTypeManage();
    }

    /**
     * 创建 FlyQiuTableConfigService 实例。
     *
     * @param configMapper FlyQiuTableConfigMapper 实例
     * @return FlyQiuTableConfigService 实例
     */
    @Bean
    @ConditionalOnMissingBean(FlyQiuTableConfigService.class)
    public FlyQiuTableConfigService flyQiuTableConfigService(FlyQiuTableConfigMapper configMapper) {
        logger.info("Creating FlyQiuTableConfigService");
        return new FlyQiuTableConfigServiceImpl(configMapper);
    }

    /**
     * 创建 FlyQiuAvueDynamicService 实例。
     *
     * @param formStoreManage FlyQiuFormStoreManage 实例
     * @return FlyQiuAvueDynamicService 实例
     */
    @Bean
    @ConditionalOnMissingBean(FlyQiuAvueDynamicService.class)
    public FlyQiuAvueDynamicService flyQiuAvueDynamicService(FlyQiuFormStoreManage formStoreManage, FlyQiuTableConfigService flyQiuTableConfigService) {
        logger.info("Creating FlyQiuAvueDynamicService");
        return new FlyQiuAvueDynamicServiceImpl(formStoreManage, flyQiuTableConfigService);
    }


    /**
     * 创建 FlyQiuFormCoreService 实例。
     *
     * @param flyQiuTableConfigService FlyQiuTableConfigService 实例
     * @param formStoreManage          FlyQiuFormStoreManage 实例
     * @return FlyQiuFormCoreService 实例
     */
    @Bean
    @ConditionalOnMissingBean(FlyQiuFormCoreService.class)
    public FlyQiuFormCoreService flyQiuFormCoreService(FlyQiuTableConfigService flyQiuTableConfigService, FlyQiuFormStoreManage formStoreManage) {
        logger.info("Creating FlyQiuFormCoreService");
        return new FlyQiuFormCoreServiceImpl(flyQiuTableConfigService, formStoreManage);
    }
}
